<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;
use App\Model\AdminInviteReward;
use App\Model\UserProfile;

class InviteOp extends BaseAction
{
    protected function render()
    {
        Admin::script($this->script($this->actionUrl));
        $invitedUserId = UserProfile::query()->where('user_profile_id',$this->row->invite_code)->value('user_id');
        $info = AdminInviteReward::query()->where([
            ['user_id','=',$invitedUserId],
            ['invited_user_id','=',$this->row->user_id],
        ])->first();

        if(empty($info)){
            $str[] = $this->buildButton('ok', '充值邀请(一天)', ['id' => $this->row->user_profile_id, 'action' => 'reward']);
        }
        $str[] = $this->buildButton('ok', '解绑', ['id' => $this->row->user_profile_id, 'action' => 'unbind']);

        return implode('<br/><br/>', $str);
    }
}
